//
//  VisitorLoginView.swift
//  ZYBWeibo
//
//  Created by xthink4 on 16/2/24.
//  Copyright © 2016年 zyb. All rights reserved.
//

import UIKit
//定义一个协议用来
protocol VisitorLoginViewDelegate:NSObjectProtocol{
    ///点击登录
    func VisitorViewLoginDidSelected()
    ///点击注册
     func VisitorViewRegistDidSelected()
    
}
class VisitorLoginView: UIView {
    
    //图标
    @IBOutlet weak var iconImage: UIImageView!
    //转环
    @IBOutlet weak var backgroundImage: UIImageView!
    //文字
    @IBOutlet weak var titleLable: UILabel!
    //定义一个代理使用weak  防止出现循环引用问题
    weak var delegate:VisitorLoginViewDelegate?
    ///首页不需要转环，其他页面需要
    //传递参数指定一个默认的值，好处是 不需要到处去修改代码
    func setupInfo(imageName:String,title:String,isHome:Bool=false){
        //判断是否是首页
        if isHome{
            backgroundImage.hidden=false
            startAnimation()
        }else{
            backgroundImage.hidden=true
            stopAnimation()
        }
        iconImage.image=UIImage(named: imageName)
        titleLable.text=title
        
    }
    ///开始动画
    func startAnimation(){
        let animation=CABasicAnimation(keyPath: "transform.rotation")
        animation.toValue=2 * M_PI
        animation.repeatCount=MAXFLOAT
        animation.duration=20.0//动画的速度
        backgroundImage.layer.addAnimation(animation, forKey: nil)
    }
    ///停止动画
    func stopAnimation(){
        backgroundImage.layer.removeAllAnimations()
    }
    ///注册按钮
    @IBAction func registBtn(sender: UIButton) {
        delegate?.VisitorViewRegistDidSelected()
    }
    ///登陆按钮
    @IBAction func loginBtn(sender: UIButton) {
        delegate?.VisitorViewLoginDidSelected()
    }
    
}
